package com.bst.bsj.bops.web.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bst.bsj.base.controller.WebBaseController;
import com.bst.bsj.bops.web.biz.PictureService;
import com.bst.bsj.common.dal.dataobject.Picture;

/**
* @Title: BannerController.java
* @Package com.bst.bsj.bops.web.controller
* @Description: 首页图管理
* @author yj
* @date 2016年5月17日 上午10:41:51
* @version V1.0
* Copyright (c) 2015, 博思堂博视界.
 */

@Scope("prototype")
@Controller
@RequestMapping(value = "/bops/sys/banner")
public class BannerController extends WebBaseController {

  @Autowired
  private PictureService pictureService;

  @RequestMapping(value = "/banner")
  public ModelAndView privilege(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    ModelAndView modelAndView = getBopsModelAndView("management/banner");
    List<Picture> pictures = new ArrayList<Picture>();
    pictures = pictureService.selectAll();
    if(pictures.size()==0){
      pictures.add(new Picture());
    }
    modelAndView.addObject("pictures", pictures);
    return modelAndView;
  }

  @RequestMapping(value = "/delete")
  public void delete(HttpServletRequest req, HttpServletResponse resp, String id) throws Exception {
    pictureService.delete(Long.valueOf(id));
  }

}
